Use case: I2C communication in polling mode ¶
This use case shows how to initialize an I2C instance and start a master transmit operation in polling mode.
Note
The API for all communication modes was renamed between HAL1 and HAL2.
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
/* Add your init and cpnfig */
HAL_I2C_Init(&hi2c);
HAL_I2CEx_ConfigAnalogFilter(&hi2c,
I2C_ANALOGFILTER_ENABLE) ;
/* Start a I2C Process */
HAL_I2C_Master_Transmit(&hi2c,
DevAddress,
&pData,
Size,
Timeout);
|
HAL_I2C_Init(&hi2c, HAL_I2C1);
HAL_I2C_SetConfig(&hi2c, &i2c_config);
HAL_I2C_EnableAnalogFilter(&hi2c);
/* Start a I2C Process */
HAL_I2C_MASTER_Transmit(&hi2c,
device_addr,
&p_data,
size_byte,
timeout_ms);
|
Key changes ¶
HAL2 uses renamed I2C APIs (for example, HAL_I2C_MASTER_Transmit() instead of HAL_I2C_Master_Transmit()).
In HAL2, the I2C configuration is applied via HAL_I2C_SetConfig().
In HAL2, the analog filter is enabled via HAL_I2C_EnableAnalogFilter().

